package com.gagakuai.bpm.demo.messageEvent.customer;


import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.task.Task;
import org.springframework.stereotype.Component;

import java.util.List;

/*
 * @program: bpm_server
 * @description: 委托
 * @author: houhong
 * @create: 2022-07-21 15:41
 */
@Slf4j
@Component(value = "instantiateProceesDelagte")
public class InstantiateProceesDelagte implements JavaDelegate {




    @Override
    public void execute(DelegateExecution execution) throws Exception {

        TaskService taskService = execution.getProcessEngineServices().getTaskService();
        // 获取当前节点的所有待办任务
        List<Task> taskList = taskService.createTaskQuery()
                .processInstanceId(execution.getProcessInstanceId())
                .list();
        for (Task task: taskList) {
            String assignee = task.getAssignee();
            log.info("assignee:"+assignee);
            // 实现保存记录表，发送语音提醒或短信提醒
        }
    }
}